package com.ngc.mall.service.impl;

import com.baomidou.mybatisplus.core.toolkit.Wrappers;
import com.ngc.mall.common.configure.mybatisPlus.BaseServiceImpl;
import com.ngc.mall.domain.SpecValueDomain;
import com.ngc.mall.dto.SpecValueDTO;
import com.ngc.mall.mapper.SpecValueMapper;
import com.ngc.mall.service.ISpecValueService;
import com.ngc.mall.vo.SpecValueVO;
import org.springframework.stereotype.Service;

import java.util.ArrayList;
import java.util.List;

@Service
public class SpecValueServiceImpl extends BaseServiceImpl<SpecValueMapper, SpecValueDomain> implements ISpecValueService {

    @Override
    public List<SpecValueVO> selectAllValueByKeyId(Long keyId){
        List<SpecValueVO> specValueVOList=new ArrayList<>();
        List<SpecValueDomain> specValueList=super.list(Wrappers.<SpecValueDomain>lambdaQuery().eq(SpecValueDomain::getSpecId,keyId).orderByDesc(SpecValueDomain::getCreateTime));
        for (SpecValueDomain domain:specValueList){
            SpecValueVO vo=SpecValueVO
                    .builder()
                    .id(domain.getId())
                    .value(domain.getValue())
                    .build();
            specValueVOList.add(vo);
        }
        return specValueVOList;
    }

    @Override
    public Long createSpecValue(SpecValueDTO dto) {
        SpecValueDomain domain=SpecValueDomain.builder().value(dto.getValue()).specId(dto.getSpecId()).build();
        super.save(domain);
        return domain.getId();
    }

    @Override
    public Boolean updateSpecValueById(SpecValueDTO dto, Long id) {
        return null;
    }



}
